﻿package com.rank.main;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang.math.RandomUtils;

import com.rank.test.UserInfo;

public class RankMain {
	// 简单测试、没有采用单元测试Junit
	public static void main(String[] args) {
		
		
		UserInfo user = new UserInfo();
		/******************注册或更新用户信息****************************/
		int userId = 0;
		long tagTime = System.currentTimeMillis();
		long startTime = tagTime;
		long endTime;
		for(int i=1;i<=1000;i++){
			Map<Double, String> users = new HashMap<Double, String>();
			for (int j = 1; j <= 100000; j++) {
				users.put((double) userId, Integer.toString(userId));
//				user.add("sort1",RandomUtils.nextInt(100),""+userId );
				userId++;
			}
			user.adds("sort_"+i,users);
			long useTime = System.currentTimeMillis()-tagTime;
			System.out.println("共写入:" + userId + "条记录   本次循环用时:"+useTime + " 插入速度:" + (100000*1000/useTime) + "条/秒");
			tagTime = System.currentTimeMillis();
		}
		
		endTime = (System.currentTimeMillis() - startTime);
		System.out.println("use:" + endTime / 1000 + "秒 speed:" + userId * 1000/ endTime + "条/秒");
		
		/******************获取用户分数和排名*************************/
		user.getScore("sort","150000");
		user.getIndex("sort","150000");

		/******************更新用户分数并重新获取排名*************************/
		user.add("sort",RandomUtils.nextInt(100),""+150000);
		user.getScore("sort","150000");
		user.getIndex("sort","150000");
		
	}
}
